<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of user model
 *
 * @author Nazmul
 */
class Contentmodel extends CI_Model {

    // tabel
    var $contentTable = 'content';
    var $contentTypeTable = 'content_type';
    // tabel field of user
    var $pkid = 'pkid';
    var $type = 'type';
    var $title = 'title';
    var $description = 'description';
    var $fk_content_type = 'fk_content_type';
    var $fk_file = 'fk_file';
    var $datetime = 'datetime';
    var $isactive = 'isactive';
    var $createtime = 'createtime';
    var $status = 'status';

    function __construct() {
        parent::__construct();
    }

    public function getContent() {
        $result = array();
        try {
            $query = $this->db->get($this->contentTable);
            if ($query->num_rows()) {
                $result = $query->result_array();
            }
        } catch (Exception $exc) {
            error_log("Contentmodel >> getContent :: line 28");
        }
        return $result;
    }

    public function getContentById($pkid) {
        $result = array();
        try {
            $this->db->where($this->status, 'active');
            $this->db->where($this->pkid, $pkid);
            $query = $this->db->get($this->contentTable);
            if ($query->num_rows()) {
                $result = $query->row_array(0);
            }
        } catch (Exception $exc) {
            error_log("Contentmodel >> getContent :: line 28");
        }
        return $result;
    }

    public function getContentType() {
        $result = array();
        try {
            $query = $this->db->get($this->contentTypeTable);
            if ($query->num_rows()) {
                $result = $query->result_array();
            }
        } catch (Exception $exc) {
            error_log("Contentmodel >> getContentType :: line 40");
        }
        return $result;
    }

    public function getContentTypeById($pkid) {
        $result = array();
        try {
            $this->db->where($this->status, 'active');
            $this->db->where($this->pkid, $pkid);
            $query = $this->db->get($this->contentTypeTable);
            if ($query->num_rows()) {
                $result = $query->row_array(0);
            }
        } catch (Exception $exc) {
            error_log("Contentmodel >> getContentType :: line 40");
        }
        return $result;
    }

    public function addContent($array) {
        try {
            $this->db->insert($this->contentTypeTable, $array);
            return true;
        } catch (Exception $exc) {
            error_log("Contentmodel >> userLogin :: line 51");
        }
        return false;
    }

    public function updateContent($updateingData, $pkid) {
        try {
            $this->db->where($this->pkid, $pkid);
            $this->db->update($this->contentTypeTable, $updateingData);
            return true;
        } catch (Exception $exc) {
            error_log("Contentmodel >> userLogin :: line 51");
        }
        return false;
    }

    public function addContentType($type) {
        try {
            $array = array();
            $array[$this->type] = $type;
            $this->db->insert($this->contentTypeTable, $array);
            return true;
        } catch (Exception $exc) {
            error_log("Contentmodel >> addContentType :: line 80");
        }
        return false;
    }

    public function updateContentType($type, $pkid, $dod = false) {
        try {
            $updateingData = array();
            if ($dod) {
                $updateingData = array($this->status => 'delete');
            } else {
                $updateingData = array($this->type => $type);
            }
            $this->db->where($this->pkid, $pkid);
            $this->db->update($this->contentTypeTable, $updateingData);
            return true;
        } catch (Exception $exc) {
            error_log("Contentmodel >> updateContentType :: line 92");
        }
        return false;
    }

}
